|
|
|
|
|
|
|
Figure 10.34
Tiling with a hexagonal tile. |
|
|
|
|
|
|
|
|
Another complication arises because the PaintPicture method copies only rectangular regions. Because these tiles are not rectangular, you cannot just use PaintPicture to copy them. If you did, PaintPicture would copy a rectangular area surrounding the tile, including some of the background area. The background would then obscure parts of the other nearby tiles. |
|
|
|
|
|
|
|
|
To avoid obscuring other tiles, you can create a mask for the tile. The mask should be the same size as the tile's bitmap. It should be black where its pixels correspond to pixels you want to draw in the tile bitmap and white where its pixels correspond to background pixels in the tile bitmap. Then instead of copying the tile in a single call to PaintPicture, you first copy the mask using the vbMergePaint raster operation. You then copy the tile bitmap using the vbSrcAnd raster operation. These two operations together copy the tile's bitmap to the destination area only in the places that correspond to black pixels in the mask. |
|
|
|
|
|
|
|
|
The TilePicture subroutine shown in the following code tiles a picture box using a tile and mask stored in image controls. The parameter cdx gives the X offset between adjacent tiles in a row. The rdx and rdy parameters give the X and Y offsets between tiles in different rows. |
|
|
|
 |
|
|
|
|
' Tile the PictureBox with the image in the image control. Private Sub TilePicture(ByVal pic As PictureBox, _
ByVal tile_image As Image, ByVal mask_image As Image, _
ByVal cdx As Integer, _
ByVal rdx As Integer, ByVal rdy As Integer)
Dim wid As Single
Dim hgt As Single
Dim x As Integer
Dim y As Integer
Dim x1 As Integer
Dim x2 As Integer
Dim startx As Integer
pic.Cls ' Clear the picture box. |
|
|
|
|
|